package com.nuoniu.sibanyun.mapper.erp;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.dto.ErpNumberSetSearchDto;
import com.nuoniu.sibanyun.entity.erp.ErpNumberSet;
import com.nuoniu.sibanyun.entity.vo.SimpleErpNumberSetVo;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 编号设置  Mapper 接口
 * </p>
 *
 * @author baiqiang
 * @since 2020-11-02
 */
@Component
@Mapper
public interface ErpNumberSetMapper extends BaseMapper<ErpNumberSet> {


//    @Select("SELECT *  FROM `pub_voucher_number_set` WHERE company_id = #{companyId} AND account_id = #{accountId} and status = 0 order by sort asc")
    List<SimpleErpNumberSetVo> listErpNumberSet(Integer companyId, Integer accountId, @Param("dto") ErpNumberSetSearchDto erpNumberSetSearchDto);

    List<SimpleErpNumberSetVo> listErpNumberParentList(Integer companyId, Integer accountId, String moduleCode);

    @Select("select * from pub_voucher_number_set where code=#{codeType} and company_id=#{companyId} and account_id=#{currentAccountId}")
    ErpNumberSet getByCode(String codeType, Integer companyId, Integer currentAccountId);

    /**
     * 规则编码初始化
     * @author 小啊刚
     * @date 2021-10-22
     */
    @Insert("insert into pub_voucher_number_set (company_id, module_name, module_code, code, name, default_code, current_code, voucher_code, create_user_id, update_user_id) " +
                " select #{companyId}, module_name, module_code, code, name, default_code, current_code, voucher_code, #{userId}, #{userId} from pub_voucher_number_set where company_id = 1 and account_id=0")
    void initCrmCode(int companyId, String companyName, int userId, String realName);
}
